Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java: enable Lombok integration #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sebaszv
Copy link

@sebaszv sebaszv commented Nov 6, 2024

NOTE: The aim here is for integration with editors
and language servers. This does not configure
for build tools like Maven. Annotation processing
must still be configured separately for compilation.

Additional JVM arguments can be specified through the
JAVA_TOOL_OPTIONS environment variable. For language
servers to be able to work with Lombok, the JVM must load
the lombok.jar. Lombok is packaged in nixpkgs, which provides
both a java wrapper for use with Lombok, as well as the JAR
itself on its own. This is what we care about. We can dynamically
make this accessible through the addition, whose path points to
the JAR that the Lombok package provides. Lombok is very useful, but can
be annoying to set-up when not working with a heavy IDE that abstracts
it all away. This eliminates the concern altogether, rather than having
to manually configure it for something like Neovim. It should just work
now.

It's a very lightweight addition that won't bloat. If the user
already is using the environment variable, the Lombok invocation will be
prepended rather than overriding the variable, hence why it is set in
shellHook, rather than simply as
JAVA_TOOL_OPTIONS = "-javaagent:${pkgs.lombok}/share/java/lombok.jar".
The lombok package also has a gcroot tied to it, preventing it from
being garbage collected, just like everything else in packages.

@sebaszv sebaszv force-pushed the java-add-lombok-integration branch 8 times, most recently from 4f1d381 to 1151ec9 Compare November 6, 2024 07:28
**NOTE**: The aim here is for integration with editors
          and language servers. This does not configure
          for build tools like Maven. Annotation processing
          must still be configured separately for compilation.

Additional JVM arguments can be specified through the
`JAVA_TOOL_OPTIONS` environment variable. For language
servers to be able to work with Lombok, the JVM must load
the `lombok.jar`. Lombok is packaged in nixpkgs, which provides
both a `java` wrapper for use with Lombok, as well as the JAR
itself on its own. This is what we care about. We can dynamically
make this accessible through the addition, whose path points to
the JAR that the Lombok package provides. Lombok is very useful, but can
be annoying to set-up when not working with a heavy IDE that abstracts
it all away. This eliminates the concern altogether, rather than having
to manually configure it for something like Neovim. It should just work
now.

It's a very lightweight addition that won't bloat. If the user
already is using the environment variable, the Lombok invocation will be
prepended rather than overriding the variable, hence why it is set in
`shellHook`, rather than simply as
`JAVA_TOOL_OPTIONS = "-javaagent:${pkgs.lombok}/share/java/lombok.jar"`.
The `lombok` package also has a gcroot tied to it, preventing it from
being garbage collected, just like everything else in `packages`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant